package util

import (
	"fmt"
	"go-toy/constant"
)

/**
 * Print message to console for different levels
 * @param level int
 * @param content string
 * @return void
 */
func PrintlnWithLevel(level int, content string) {
	am := Message{}
	am.Reset()
	am.SetLevel(level)
	am.Content = content

	fullContent := am.Prefix + " " + am.Content
	// Color types: 30: glay, 31: red, 32: green, 33: yellow, 34: blue, 35: purple
	switch level {
	case constant.MsgLevelInfo:
		fmt.Println("\033[33m" + fullContent + "\033[0m")
	case constant.MsgLevelSuccess:
		fmt.Println("\033[32m" + fullContent + "\033[0m")
	case constant.MsgLevelDebug:
		fmt.Println("\033[29m" + fullContent + "\033[0m")
	case constant.MsgLevelWarning:
		fmt.Println("\033[31m" + fullContent + "\033[0m")
	case constant.MsgLevelError:
		fmt.Println("\033[31m" + fullContent + "\033[0m")
	case constant.MsgLevelTrace:
		fmt.Println("\033[31m" + fullContent + "\033[0m")
	case constant.MsgLevelFatal:
		fmt.Println("\033[31m" + fullContent + "\033[0m")
	default:
		fmt.Println("\035[29m" + fullContent + "\033[0m")
	}
}

/**
 * Print message to console with INFO level
 * @param content string
 * @return void
 */
func Println(content string) {
	PrintlnWithLevel(0, content)
}

/**
 * Print message to console with SUCCESS level
 * @param content string
 * @return void
 */
func PrintlnSuccess(content string) {
	PrintlnWithLevel(1, content)
}

/**
 * Print message to console with DEBUG level
 * @param content string
 * @return void
 */
func PrintlnDebug(content string) {
	PrintlnWithLevel(2, content)
}

/**
 * Print message to console with WARNING level
 * @param content string
 * @return void
 */
func PrintlnWarning(content string) {
	PrintlnWithLevel(3, content)
}

/**
 * Print message to console with ERROR level
 * @param content string
 * @return void
 */
func PrintlnError(content string) {
	PrintlnWithLevel(4, content)
}

/**
 * Print message to console with TRACE level
 * @param content string
 * @return void
 */
func PrintlnTrace(content string) {
	PrintlnWithLevel(5, content)
}

/**
 * Print message to console with FATAL level
 * @param content string
 * @return void
 */
func PrintlnFatal(content string) {
	PrintlnWithLevel(6, content)
}
